package com.opNaga.bpmn.actions.view;

import com.opNaga.bpmn.panel.BPMPPanel;
import y.view.Graph2DView;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.Dictionary;
import java.util.Hashtable;

/**
 * User: Junyi BEI
 * Date: 20/03/2012
 * Time: 15:52
 */
public class FitContent extends AbstractAction {
  private JTabbedPane tabbedPane;
  private Dictionary<Integer, Graph2DView> views = new Hashtable<Integer, Graph2DView>();

  public FitContent(JTabbedPane tabbedPane) {
    this.tabbedPane = tabbedPane;
    int tabCount = tabbedPane.getTabCount();
    for(int t = 0; t < tabCount; t++) {
      BPMPPanel bpmpPanel = (BPMPPanel) tabbedPane.getComponentAt(t);
      Graph2DView view = bpmpPanel.getView();
      views.put(t, view);
    }
  }

  public void actionPerformed(ActionEvent e) {
    Graph2DView view = views.get(tabbedPane.getSelectedIndex());
    view.fitContent();
    view.updateView();
  }
}